Allow different pipeline layouts
authorMatthias Clasen <mclasen@redhat.com>
Fri, 22 Sep 2017 14:35:19 +0000 (10:35 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 23 Sep 2017 02:16:09 +0000 (22:16 -0400)
These are differentiated by the number of textures; currently
we have shaders with 0 and 1 textures.

gsk/gskvulkanpipeline.c
gsk/gskvulkanpipelineprivate.h
gsk/gskvulkanrender.c
gsk/gskvulkanrenderpass.c
gsk/gskvulkanrenderpassprivate.h

index ce41190f671fce5c635bf27b93254a6f746172ee..6a834c5d9ebc40440d8d94227c9b553949606c14 100644 (file)
@@ -198,6 +198,7 @@ gsk_vulkan_pipeline_get_pipeline_layout (GskVulkanPipeline *self)
 
 GskVulkanPipelineLayout *
 gsk_vulkan_pipeline_layout_new (GdkVulkanContext      *context,
+                                guint                  layout_count,
                                 VkDescriptorSetLayout *descriptor_set_layout)
 {
   GskVulkanPipelineLayout *self;
@@ -212,7 +213,7 @@ gsk_vulkan_pipeline_layout_new (GdkVulkanContext      *context,
   GSK_VK_CHECK (vkCreatePipelineLayout, device,
                                         &(VkPipelineLayoutCreateInfo) {
                                             .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
-                                            .setLayoutCount = 1,
+                                            .setLayoutCount = layout_count,
                                             .pSetLayouts = descriptor_set_layout,
                                             .pushConstantRangeCount = gst_vulkan_push_constants_get_range_count (),
                                             .pPushConstantRanges = gst_vulkan_push_constants_get_ranges ()
index 825fa15ecd1834ffd235f2dc5e14b37071021c1b..648f04ddf1c0a21b492f884cce0a6725349a0695 100644 (file)
@@ -35,6 +35,7 @@ gsk_vulkan_handle_result (VkResult    res,
 #define GSK_VK_CHECK(func, ...) gsk_vulkan_handle_result (func (__VA_ARGS__), G_STRINGIFY (func))
 
 GskVulkanPipelineLayout *       gsk_vulkan_pipeline_layout_new          (GdkVulkanContext               *context,
+                                                                         guint                           layout_count,
                                                                          VkDescriptorSetLayout          *descriptor_set_layout);
 GskVulkanPipelineLayout *       gsk_vulkan_pipeline_layout_ref          (GskVulkanPipelineLayout        *self);
 void                            gsk_vulkan_pipeline_layout_unref        (GskVulkanPipelineLayout        *self);
index 500eff6db191efa7d1f96fc726699a5eda6e0e5a..5a811cf14281c4c743a40e65589de95c834c17a2 100644 (file)
@@ -41,14 +41,14 @@ struct _GskVulkanRender
   VkFence fence;
   VkRenderPass render_pass;
   VkDescriptorSetLayout descriptor_set_layout;
-  GskVulkanPipelineLayout *layout;
+  GskVulkanPipelineLayout *layout[3]; /* indexed by number of textures */
   GskVulkanUploader *uploader;
   GskVulkanBuffer *vertex_buffer;
 
   GHashTable *descriptor_set_indexes;
   VkDescriptorPool descriptor_pool;
   uint32_t descriptor_pool_maxsets;
-  VkDescriptorSet *descriptor_sets;  
+  VkDescriptorSet *descriptor_sets;
   gsize n_descriptor_sets;
   GskVulkanPipeline *pipelines[GSK_VULKAN_N_PIPELINES];
 
@@ -194,7 +194,15 @@ gsk_vulkan_render_new (GskRenderer      *renderer,
                                              &self->descriptor_set_layout);
 
 
-  self->layout = gsk_vulkan_pipeline_layout_new (self->vulkan, &self->descriptor_set_layout);
+  for (guint i = 0; i < 3; i++)
+    {
+      VkDescriptorSetLayout layouts[3] = {
+        self->descriptor_set_layout,
+        self->descriptor_set_layout,
+        self->descriptor_set_layout
+      };
+      self->layout[i] = gsk_vulkan_pipeline_layout_new (self->vulkan, i, layouts);
+    }
 
   self->uploader = gsk_vulkan_uploader_new (self->vulkan, self->command_pool);
 
@@ -336,45 +344,46 @@ gsk_vulkan_render_get_pipeline (GskVulkanRender       *self,
 {
   static const struct {
     const char *name;
+    guint num_textures;
     GskVulkanPipeline * (* create_func) (GskVulkanPipelineLayout *layout, const char *name, VkRenderPass render_pass);
   } pipeline_info[GSK_VULKAN_N_PIPELINES] = {
-    { "blend", gsk_vulkan_blend_pipeline_new },
-    { "blend-clip", gsk_vulkan_blend_pipeline_new },
-    { "blend-clip-rounded", gsk_vulkan_blend_pipeline_new },
-    { "color", gsk_vulkan_color_pipeline_new },
-    { "color-clip", gsk_vulkan_color_pipeline_new },
-    { "color-clip-rounded", gsk_vulkan_color_pipeline_new },
-    { "linear", gsk_vulkan_linear_gradient_pipeline_new },
-    { "linear-clip", gsk_vulkan_linear_gradient_pipeline_new },
-    { "linear-clip-rounded", gsk_vulkan_linear_gradient_pipeline_new },
-    { "color-matrix", gsk_vulkan_effect_pipeline_new },
-    { "color-matrix-clip", gsk_vulkan_effect_pipeline_new },
-    { "color-matrix-clip-rounded", gsk_vulkan_effect_pipeline_new },
-    { "border", gsk_vulkan_border_pipeline_new },
-    { "border-clip", gsk_vulkan_border_pipeline_new },
-    { "border-clip-rounded", gsk_vulkan_border_pipeline_new },
-    { "inset-shadow", gsk_vulkan_box_shadow_pipeline_new },
-    { "inset-shadow-clip", gsk_vulkan_box_shadow_pipeline_new },
-    { "inset-shadow-clip-rounded", gsk_vulkan_box_shadow_pipeline_new },
-    { "outset-shadow", gsk_vulkan_box_shadow_pipeline_new },
-    { "outset-shadow-clip", gsk_vulkan_box_shadow_pipeline_new },
-    { "outset-shadow-clip-rounded", gsk_vulkan_box_shadow_pipeline_new },
-    { "blur", gsk_vulkan_blur_pipeline_new },
-    { "blur-clip", gsk_vulkan_blur_pipeline_new },
-    { "blur-clip-rounded", gsk_vulkan_blur_pipeline_new },
-    { "mask", gsk_vulkan_text_pipeline_new },
-    { "mask-clip", gsk_vulkan_text_pipeline_new },
-    { "mask-clip-rounded", gsk_vulkan_text_pipeline_new },
-    { "blend", gsk_vulkan_color_text_pipeline_new },
-    { "blend-clip", gsk_vulkan_color_text_pipeline_new },
-    { "blend-clip-rounded", gsk_vulkan_color_text_pipeline_new },
+    { "blend",                      1, gsk_vulkan_blend_pipeline_new },
+    { "blend-clip",                 1, gsk_vulkan_blend_pipeline_new },
+    { "blend-clip-rounded",         1, gsk_vulkan_blend_pipeline_new },
+    { "color",                      0, gsk_vulkan_color_pipeline_new },
+    { "color-clip",                 0, gsk_vulkan_color_pipeline_new },
+    { "color-clip-rounded",         0, gsk_vulkan_color_pipeline_new },
+    { "linear",                     0, gsk_vulkan_linear_gradient_pipeline_new },
+    { "linear-clip",                0, gsk_vulkan_linear_gradient_pipeline_new },
+    { "linear-clip-rounded",        0, gsk_vulkan_linear_gradient_pipeline_new },
+    { "color-matrix",               1, gsk_vulkan_effect_pipeline_new },
+    { "color-matrix-clip",          1, gsk_vulkan_effect_pipeline_new },
+    { "color-matrix-clip-rounded",  1, gsk_vulkan_effect_pipeline_new },
+    { "border",                     0, gsk_vulkan_border_pipeline_new },
+    { "border-clip",                0, gsk_vulkan_border_pipeline_new },
+    { "border-clip-rounded",        0, gsk_vulkan_border_pipeline_new },
+    { "inset-shadow",               0, gsk_vulkan_box_shadow_pipeline_new },
+    { "inset-shadow-clip",          0, gsk_vulkan_box_shadow_pipeline_new },
+    { "inset-shadow-clip-rounded",  0, gsk_vulkan_box_shadow_pipeline_new },
+    { "outset-shadow",              0, gsk_vulkan_box_shadow_pipeline_new },
+    { "outset-shadow-clip",         0, gsk_vulkan_box_shadow_pipeline_new },
+    { "outset-shadow-clip-rounded", 0, gsk_vulkan_box_shadow_pipeline_new },
+    { "blur",                       1, gsk_vulkan_blur_pipeline_new },
+    { "blur-clip",                  1, gsk_vulkan_blur_pipeline_new },
+    { "blur-clip-rounded",          1, gsk_vulkan_blur_pipeline_new },
+    { "mask",                       1, gsk_vulkan_text_pipeline_new },
+    { "mask-clip",                  1, gsk_vulkan_text_pipeline_new },
+    { "mask-clip-rounded",          1, gsk_vulkan_text_pipeline_new },
+    { "blend",                      1, gsk_vulkan_color_text_pipeline_new },
+    { "blend-clip",                 1, gsk_vulkan_color_text_pipeline_new },
+    { "blend-clip-rounded",         1, gsk_vulkan_color_text_pipeline_new },
   };
 
   g_return_val_if_fail (type < GSK_VULKAN_N_PIPELINES, NULL);
 
   if (self->pipelines[type] == NULL)
     {
-      self->pipelines[type] = pipeline_info[type].create_func (self->layout,
+      self->pipelines[type] = pipeline_info[type].create_func (self->layout[pipeline_info[type].num_textures],
                                                                pipeline_info[type].name,
                                                                self->render_pass);
     }
@@ -561,7 +570,7 @@ gsk_vulkan_render_draw (GskVulkanRender   *self,
 
       for (l = self->render_passes; l; l = l->next)
         {
-          gsk_vulkan_render_pass_draw (l->data, self, self->vertex_buffer, self->layout, command_buffer);
+          gsk_vulkan_render_pass_draw (l->data, self, self->vertex_buffer, 3, self->layout, command_buffer);
         }
 
       vkCmdEndRenderPass (command_buffer);
@@ -654,7 +663,8 @@ gsk_vulkan_render_free (GskVulkanRender *self)
 
   g_clear_pointer (&self->uploader, gsk_vulkan_uploader_free);
 
-  g_clear_pointer (&self->layout, gsk_vulkan_pipeline_layout_unref);
+  for (i = 0; i < 3; i++)
+    g_clear_pointer (&self->layout[i], gsk_vulkan_pipeline_layout_unref);
 
   vkDestroyRenderPass (device,
                        self->render_pass,
index f3b3dea25da1e9d9100f5fcbdd3edf803ded4499..245c753caec19736c8718032049c7c773d341b89 100644 (file)
@@ -1034,7 +1034,8 @@ void
 gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
                              GskVulkanRender         *render,
                              GskVulkanBuffer         *vertex_buffer,
-                             GskVulkanPipelineLayout *layout,
+                             guint                    layout_count,
+                             GskVulkanPipelineLayout **layout,
                              VkCommandBuffer          command_buffer)
 {
   GskVulkanPipeline *current_pipeline = NULL;
@@ -1072,7 +1073,7 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_layout_get_pipeline_layout (layout),
+                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -1105,7 +1106,7 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_layout_get_pipeline_layout (layout),
+                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -1138,7 +1139,7 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_layout_get_pipeline_layout (layout),
+                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -1172,7 +1173,7 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_layout_get_pipeline_layout (layout),
+                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -1205,7 +1206,7 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_layout_get_pipeline_layout (layout),
+                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -1313,9 +1314,10 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
           break;
 
         case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
-          gsk_vulkan_push_constants_push (&op->constants.constants,
-                                          command_buffer, 
-                                          gsk_vulkan_pipeline_layout_get_pipeline_layout (layout));
+          for (int i = 0; i < layout_count; i++)
+            gsk_vulkan_push_constants_push (&op->constants.constants,
+                                            command_buffer, 
+                                            gsk_vulkan_pipeline_layout_get_pipeline_layout (layout[i]));
           break;
 
         default:
index 48a246124662f717e713940b4fcdce2102b6b096..d38189966c92547f7d1c7ede6ac78c86a9ec94fc 100644 (file)
@@ -36,7 +36,8 @@ void                    gsk_vulkan_render_pass_reserve_descriptor_sets  (GskVulk
 void                    gsk_vulkan_render_pass_draw                     (GskVulkanRenderPass    *self,
                                                                          GskVulkanRender        *render,
                                                                          GskVulkanBuffer        *vertex_buffer,
-                                                                         GskVulkanPipelineLayout *layout,
+                                                                         guint                   layout_count,
+                                                                         GskVulkanPipelineLayout **layout,
                                                                          VkCommandBuffer         command_buffer);
 
 G_END_DECLS